<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>系统首页</title>
    <link rel="stylesheet" href="{$CSS}/bootstrap3.3.7.min.css">
    <style>
        td,th{
			text-align: center;vertical-align: middle !important;
			}
        .paging{
           list-style:none;
           display:inline ;
           padding-left:2px    
        }
/*
        .paging:after{
            content:"";
            clear: both
        }
*/
        .paging li{
            display:inline-block
        }
        .paging a{
            padding:5px 10px;
            border: 1px solid #ddd;
            margin-left: -1px;
            text-decoration: none;
        }
        .active{
            border-color: #337ab7 !important;
        }
    </style>
</head>

<body>
    <div style="padding:10px;border-bottom:1px solid #eee;font-size:15px;font-weight:700">下级用户管理</div>
    <div style="padding:20px">
        <form class="form-inline" method="get" action="{$target}" name="Form" id="Form1">
            <div class="form-group">
                <label for="exampleInputName2">用户名</label>
				{$tj->text('un','class="form-control" placeholder="用户名"')}		
            </div>
			<div class="form-group">
                <label for="exampleInputName2">手机</label>
				{$tj->text('telephone','class="form-control" placeholder="手机"')}		
            </div>
            <div class="form-group">
                <label for="exampleInputEmail2">用户级别</label>
				{$tj->select($user_level,'level_id','class="form-control"')}
            </div>
            <div class="form-group">
                <label for="exampleInputEmail2">状态</label>
				{$tj->select($zt_arr,'isstop','class="form-control"')}	
            </div>
            <button type="submit" class="btn btn-primary">查询</button>
            <button type="button" class="btn btn-primary" onclick="stop('a',this)" id="del">停用</button>
            <button type="button" class="btn btn-primary" onclick="tostart('a',this)" id="del">启用</button>
            <button type="button" class="btn btn-danger" onclick="todel('a',this)" id="del">删除</button>
        </form>
        <div style="margin-top:15px">
            <table class="table table-bordered table-hover">
              <thead>
                <tr>
                  <th>ID</th>
                  <th>用户名</th>
                  <th>开户时间</th>
                  <th>用户级别</th>
                  <th>到期时间</th>
                  <th>手机</th>
                  <th>备注</th>
                  <th>所属员工（代理）</th>
                  <th>状态</th>
                  <th class="col-md-2">操作</th>
                </tr>
              </thead>
              <tbody>
			{loop $res as $r}
                <tr>
                  <td scope="row"><input type='checkbox' name='checkbox' value='{$r->id}' />{$r->id}</td>
                  <td><a href="add-{$r->id}.html">{$r->un}</a></td>
                  <!--<td>{date('Y-m-d H:i:s',strtotime($r->rtime))}</td>-->
				  <td>{$r->rtime}</td>
                  <td>{$user_level[$r->level_id]}</td>
                    <td>{if trim($r->mendtime)!=''}
					  <!--{date('Y-m-d',strtotime($r->mendtime))}-->
					   <?php $datetime = new \DateTime($r->mendtime);echo $datetime->format('Y-m-d');?>
					  {/if}
		          </td>
                    <td>{$r->telephone}</td>
                    <td>{$r->alias}</td>
                  <td>{$agency_arr[$r->agid]}</td>
                  <td><span {if $r->isstop=='1'}style="color:red;"{/if} >{$zt_arr[$r->isstop]}</span></td>
                  <td>
                      <a class="btn btn-success btn-sm" href="{$loginurl}/login.html?uid={$r->id}&upwd={$r->pwd}" target="_blank">越权登录</a>
                      <a class="btn btn-info btn-sm" href="javascript:tochongzhi({$r->id});">升级续费</a>
                      <a class="btn btn-primary btn-sm" href="add-{$r->id}.html">编辑</a>
                  </td>
                </tr>
			{/loop}
              </tbody>
            </table>
        </div>
        <div>
            <div style="display: inline-block">
                <span>{$p->totalnum}条/{$p->totalpage}页</span> 
            </div>
			<ul class="paging">
           {P weidogsadmin}
			</ul>
        </div>
    </div>
</body>
</html>
<script src="/cdn/jquery.js"></script>
<script src="/layui/layui.js"></script>
<script src="/js/ajax.js"></script>
<script type="text/javascript">
    layui.use('form', function(){
      var form = layui.form;
      
      //监听提交
      form.on('submit(formDemo)', function(data){
        layer.msg(JSON.stringify(data.field));
        return false;
      });

    });

</script>
<script type="text/javascript">
function stop(id,o){
	if(id=='a'){
		var ids = [];
		$('td').find('input[type="checkbox"]:checked').each(function(){
			ids[ids.length] = $(this).val();
		});
		if(ids.length == 0){
			tusi('请选择！');
			return false;
		}
		if(confirm('确定停用这些用户吗？')){
			ajax('zuizhongcaozuo-stop.html',{ id:ids.join(',')},function(data){
				if(data == 'ok'){
					tusi('操作成功');
					setTimeout(function(){
						location.reload();
					},500);
				}
			});	
		}
	}
}
function tostart(id,o){
	if(id=='a'){
		var ids = [];
		$('td').find('input[type="checkbox"]:checked').each(function(){
			ids[ids.length] = $(this).val();
		});
		if(ids.length == 0){
			tusi('请选择！');
			return false;
		}
		if(confirm('确定启用这些用户吗？')){
			ajax('zuizhongcaozuo-start.html',{ id:ids.join(',')},function(data){
				if(data == 'ok'){
					tusi('操作成功');
					setTimeout(function(){
						location.reload();
					},500);
				}
			});	
		}
	}
}
function todel(id,o){
	if(id=='a'){
		var ids = [];
		$('td').find('input[type="checkbox"]:checked').each(function(){
			ids[ids.length] = $(this).val();
		});
		if(ids.length == 0){
			tusi('请选择！');
			return false;
		}
		if(confirm('确定删除这些用户吗？')){
			ajax('zuizhongcaozuo-del.html',{ id:ids.join(',')},function(data){
				if(data == 'ok'){
					tusi('操作成功');
					setTimeout(function(){
						location.reload();
					},500);
				}
			});	
		}
	}
}
function tochongzhi(id){
   layer.open({
        type: 2,
        title: '升级续费',
        shadeClose: true,
        shade: 0.2,
        area: ['700px', '600px'],
        content: 'zuizhongchongzhi.html?id='+id
    });
}
</script>